//
//  ViewController.m
//  UI05_UIControl及子类课后作业
//
//  Created by dllo on 16/5/9.
//  Copyright © 2016年 jcl. All rights reserved.
//

#import "ViewController.h"
#import "SimpleUISlider.h"
#import "SimpleSegmented.h"
#import "SimpleView.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

//    [self creatOfSlider];
    [self createSegment];
    [self creatView];
    
}


- (void)creatOfSlider {
    
    SimpleUISlider *slideRed = [[SimpleUISlider alloc]initWithFrame:CGRectMake((self.view.frame.size.width - 200) / 2, 100, 200, 100)];
    
    [self.view addSubview:slideRed];
    
    [slideRed release];
    
    slideRed.minimumTrackTintColor = [UIColor redColor];
    
    [slideRed addTarget:self action:@selector(handleRed:) forControlEvents:UIControlEventValueChanged];
    
    
    
    
    

    SimpleUISlider *sliderYellow = [[SimpleUISlider alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 200) / 2, 200, 200, 100)];
    
    [self.view addSubview:sliderYellow];
    
    [sliderYellow release];
    
    sliderYellow.minimumTrackTintColor = [UIColor yellowColor];
    
    [sliderYellow addTarget:self action:@selector(handleYellow:) forControlEvents:UIControlEventValueChanged];
    
    
    
    
    
    SimpleUISlider *sliderBlue = [[SimpleUISlider alloc]initWithFrame:CGRectMake((self.view.frame.size.width - 200) / 2, 300, 200, 100)];
    
    [self.view addSubview:sliderBlue];
    
    [sliderBlue release];
    
    sliderBlue.minimumTrackTintColor = [UIColor blueColor];
    
    [sliderBlue addTarget:self action:@selector(handleBiue:) forControlEvents:UIControlEventValueChanged];
    
    
    
    
    SimpleUISlider *slider4 = [[SimpleUISlider alloc]initWithFrame:CGRectMake((self.view.frame.size.width - 200) / 2, 400, 200, 100)];
    
    [self.view addSubview:slider4];
    
    [slider4 release];
    
    [slider4 addTarget:self action:@selector(handleAlpha:) forControlEvents:UIControlEventValueChanged];
    
    
    
}

- (void)handleRed:(SimpleUISlider *)sliderRed {
    
    self.view.backgroundColor = [UIColor redColor];
    
    
}

- (void)handleYellow:(SimpleUISlider *)sliderYellow {
    
    self.view.backgroundColor = [UIColor yellowColor];
    
                                 
}

- (void)handleBiue:(SimpleUISlider *)sliderBlue {
    
    self.view.backgroundColor = [UIColor blueColor];
}

- (void)handleAlpha:(SimpleUISlider *)alpha {
    
//    self.view.alpha = [UIColor colorWithRed:alpha.value * 0.6  green:alpha.value * 0.4 blue:alpha.value * 0.5 alpha:alpha.value / 100.0f];
//    
    self.view.alpha = alpha.value / 100.0f;

}


- (void)createSegment {
    
    
    
    SimpleSegmented *segcustom = [[SimpleSegmented alloc]initWithItems:@[@"登录", @"注册", @"忘记密码"]];
    
    segcustom.tag = 0;
    segcustom.frame = CGRectMake((self.view.frame.size.width - 300) / 2, 200, 300, 80);
    
    [self.view addSubview:segcustom];
    
    [segcustom release];
    
    segcustom.selectedSegmentIndex = 0;
    
    [segcustom addTarget:self action:@selector(handleSeg:) forControlEvents:UIControlEventValueChanged];
    
  
}




    


- (void)creatView {
    
    SimpleView *view1 = [[SimpleView alloc] initWithFrame:self.view.bounds];
    
    view1.tag = 1;
    
    [self.view addSubview:view1];
    
    view1.backgroundColor = [UIColor whiteColor];
    [view1 release];
    
    UILabel *labelV1 = [[UILabel alloc] initWithFrame:CGRectMake(40, 100, 100, 50)];
    [view1 addSubview:labelV1];
    [labelV1 release];
    labelV1.text = @"用户名";
    
    
    UILabel *lableV2 = [[UILabel alloc] initWithFrame:CGRectMake(40, 200, 100, 50)];
    [view1 addSubview:lableV2];
    [lableV2 release];
    lableV2.text = @"密码";
    
    UITextField *text1 = [[UITextField alloc] initWithFrame:CGRectMake(200, 100, 300, 50)];
    [view1 addSubview:text1];
    [text1 release];
    text1.placeholder = @"请输入用户名";
    
    UIButton *buttonV1 = [[UIButton alloc] initWithFrame:CGRectMake(50, 400, 100, 60)];
    
    [view1 addSubview:buttonV1];
    
    [buttonV1 release];
    
    buttonV1.backgroundColor = [UIColor blackColor];
    
    [buttonV1 setTitle:@"取消" forState:UIControlStateNormal];
    
    [buttonV1 addTarget:self action:@selector(handleuse:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    
    SimpleView *view2 = [[SimpleView alloc] initWithFrame:self.view.bounds];
    
    view2.tag = 2;
    
    view2.backgroundColor = [UIColor yellowColor];
    
    [self.view addSubview:view2];
    
    [view2 release];
    
    UILabel *lableV4 = [[UILabel alloc] initWithFrame:CGRectMake(50, 300, 80, 40)];
    
    [self.view addSubview:lableV4];
    
    [lableV4 release];
    
    lableV4.text = @"电子邮箱";
    
    UITextField *text2 = [[UITextField alloc] initWithFrame:CGRectMake(200, 300, 200, 40)];
    [self.view addSubview:text2];
    [text2 release];
    text2.placeholder = @"请输入邮箱";
    
    UIButton *buttonV2 = [[UIButton alloc] initWithFrame:CGRectMake(100, 400, 80, 40)];
    [self.view addSubview:buttonV2];
    [buttonV2 setTitle:@"取消" forState:UIControlStateNormal];
    [buttonV2 release];
    
    
    
    
    SimpleView *view3 = [[SimpleView alloc] initWithFrame:self.view.bounds];
    
    view3.tag = 3;
    
    [self.view addSubview:view3];
    view3.backgroundColor = [UIColor cyanColor];
    [view3 release];
    
    
    UILabel *lableV3 = [[UILabel alloc] initWithFrame:CGRectMake(40, 60, 100, 50)];
    [self.view addSubview:lableV3];
    [lableV3 release];
    lableV3.text = @"用户名";
    
    UITextField *text3 = [[UITextField alloc] initWithFrame:CGRectMake(200, 60, 300, 50)];
    text3.placeholder = @"请输入用户名";
    [self.view addSubview:text3];
    [text3 release];
    
    UIButton *butonOfC = [[UIButton alloc] initWithFrame:CGRectMake(300, 500, 60, 40)];
    [butonOfC setTitle:@"取消" forState:UIControlStateNormal];
    [self.view addSubview:butonOfC];
    [butonOfC release];
    
    [butonOfC addTarget:self action:@selector(handleC:) forControlEvents:UIControlEventTouchUpInside];
    
    
}

- (void)handleC:(UIButton *)buttonqu {
    
    [self.view bringSubviewToFront:[self.view viewWithTag:1]];
    
    
    
    
}



//- (void)handleSeg:(SimpleSegmented *)segment {
//    
//    if (segment.selectedSegmentIndex == 0) {
//        
//        [self.view bringSubviewToFront:[self.view viewWithTag:1]];
//        
//    }
//    if (segment.selectedSegmentIndex == 1) {
//        [self.view bringSubviewToFront:[self.view viewWithTag:2]];
//    }
//    if (segment.selectedSegmentIndex == 2) {
//        [self.view bringSubviewToFront:[self.view viewWithTag:3]];
//        
//    }
//
//
//}








@end
